<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
    }
    #box{
        width: 400px;
        height: 400px;
        margin-left: 100px;
        margin-top: 100px;
        position: relative;
    }
    #smallBox{
        width: 400px;
        height: 400px;
    }
    #shadow{
        width: 50px;
        height: 50px;
        position: absolute;
        background: rgba(110,110,110,.6);
        display: none;
        left: 0;
        top: 0;
        border-radius: 50%;
    }
    #smallImg{
        width: 400px;
        height: 400px;
    }
    #bigBox{
        width: 100px;
        height: 100px;
        position: absolute;
        top: 0;
        left: 0;
        overflow: hidden;
        display: none;
        border-radius: 50%;
    }
    #bigImg{
        width: 800px;
        height: 800px;
        position: absolute;
    }
    #nav{
        width: 400px;
        height: 100px;
    }
    #nav li{
        width: 100px;
        height: 100px;
        float: left;
    }
    #nav img{
        width: 100px;
        height: 100px;
    }

    .left{
        position: absolute;
        left: 0;
    }

    .right{
        position: absolute;
        width: 400px;
        left: 700px;
        margin-top: 100px;
    }
    p{
        margin-top: 50px;
    }
</style>
<body>
    <div class="wrap">
        <div class="left">
            <div id="box">
                <div id="smallBox">
                    <img src="../img/4.jpg" alt="" id="smallImg">
                    <div id="shadow"></div>
                    <div id="bigBox">
                        <img src="../img/4.jpg" alt="" id="bigImg">
                </div>
                </div>
              
                <ul id="nav">
                    <li data-small="../img/4.jpg" data-big="../img/4.jpg">
                            <img src="../img/4.jpg" alt="">
                    </li>
                    <li data-small="../img/5.jpg" data-big="../img/5.jpg">
                            <img src="../img/5.jpg" alt="">
                    </li>
                    <li data-small="../img/6.jpg" data-big="../img/6.jpg">
                            <img src="../img/6.jpg" alt="">
                    </li>
                    <li data-small="../img/7.jpg" data-big="../img/7.jpg">
                            <img src="../img/7.jpg" alt="">
                    </li>
                </ul>
            </div>
        </div>

        <div class="right">
            <h2>法国拉杜蓝乔核桃油非婴儿婴幼儿辅食食用儿童宝宝无添加抖音同款</h2>
            <p>
                商品价格： <span>￥500</span>
            </p>
            <p>
                交易数量： <span>￥500</span>
            </p>
            <p><button class="reduce">-</button><input type="num" value="1"><button class="add">+</button></p>
            <p>
                <button class="buyNow">立即购买</button>
                <button class="addCar">加入购物车</button>

            </p>
        </div>
    </div>
</body>
<script>
    var shadow=document.getElementById("shadow");
    var smallBox=document.getElementById("smallBox");
    var bigBox=document.getElementById("bigBox");
    var navList=document.querySelectorAll("#nav li");
    var smallImg=document.getElementById("smallImg");
    var bigImg=document.getElementById("bigImg");
    var box=document.getElementById("box");
    smallBox.onmouseout=function(){
        shadow.style.display="none";
        bigBox.style.display="none";
    }
    smallBox.onmousemove=function(e){
        bigBox.style.display="block";
        shadow.style.display="block";
        var evt=e || window.event;
        var x=evt.pageX-shadow.offsetWidth/2-box.offsetLeft;
        var y=evt.pageY-shadow.offsetHeight/2-box.offsetTop;
        var maxX=smallBox.offsetWidth-shadow.offsetWidth;
        var maxY=smallBox.offsetHeight-shadow.offsetHeight;
        if(x<=0){
            x=0;
        }
        if(y<=0){
            y=0;
        }
        if(x>=maxX){
            x=maxX;
        }
        if(y>=maxY){
            y=maxY;
        }
        shadow.style.left=x+"px";
        shadow.style.top=y+"px";
        bigImg.style.left=-(bigBox.offsetWidth/shadow.offsetWidth*x)+"px";
        bigImg.style.top=-(bigBox.offsetHeight/shadow.offsetHeight*y)+"px";

       var bigBoxX=x-bigBox.offsetWidth/2+shadow.offsetWidth/2;
       var bigBoxY=y-bigBox.offsetHeight/2+shadow.offsetHeight/2;
        bigBox.style.left=bigBoxX+"px";
        bigBox.style.top=bigBoxY+"px";
    }
    for(let i=0;i<navList.length;i++){
        let li=navList[i];
        li.onmousemove=function(){
           var dataSmall= li.getAttribute("data-small");
           var dataBig=li.getAttribute("data-big")
            smallImg.src=dataSmall;
            bigImg.src=dataBig;
        }
    }
    var add=document.querySelector(".add");
    var reduce=document.querySelector(".reduce");
    add.onclick=function(){
        var conInput=this.previousElementSibling;
        var con=conInput.value*1;
        conInput.value=con+1;
    }
    reduce.onclick=function(){
        var conInput=this.nextElementSibling;
        var con=conInput.value*1;
        conInput.value=con-1;
    }
</script>
</html>